var app = getApp()

Page({
    data: {
        checked: !0,
        project_address:'湖北',
        ipone:[],
        name:[],
        sunews:[],
        checked: !0,
        userInfo: {},
        id:"",
        orderInfo: {},
        userImageBase64:""
    },
   onShow:function(){
     
   },
    
    
   
   onLoad: function (options) {
      this.setData({
        id: options.iid
      })  

      console.log('onLoad' + options.iid)
      var that = this
      //调用应用实例的方法获取全局数据
      app.getUserInfo(function (userInfo) {
        console.log(userInfo)
        //更新数据
        that.setData({
          userInfo: userInfo
        })
      })
    // 

      
    },
    toast: function() {
        wx.navigateTo({
            url: "../protocol/protocol"
        });
    },
    checkboxChange: function(a) {
        this.data.checked ? this.setData({
            checked: !1
        }) : this.setData({
            checked: !0
        });
    },
    
    formSubmit: function(t) {
     
        var e = this, i = t.detail.value;
        var thisPage = this;
        
        if (1 != e.validataInput("name", i.name) && 1 != e.validataInput("tel", i.tel)) {
          wx.request({
            url: 'http://localhost:8080/insertAppointment',
        data: {
           name: this.data.name,
           cphone: this.data.ipone,
           hid: this.data.id,
           aimage: this.data.userImageBase64,
           yname: this.data.userInfo.nickName
        },
        method: 'GET',
        header: {
          'content-type': 'application/json' // 默认值
        },
                success: function(a) {
                 
                 
                },
                 complete: function (res) {
                 
               
                 if (res.data==1){
                   wx.showToast({
                     title: '预约成功',
                     icon: 'loading',
                     duration: 2000
                    
                   })
                 } else if (res.data == 0){
                   wx.showToast({
                     title: '已存在预约请求',
                     icon: 'loading',
                     duration: 2000
                   })
                 }
                }
            });
        }
    },
    validataInput: function(a, t) {
     
        var e = 0, i = this;
        switch (a) {
          case "name":
            "" === t && (e = 1, i.valiMsg("请输入姓名！")), t.length > 16 && (e = 1, i.valiMsg("您输入的姓名过长！"));
            break;

          case "check":
            !1 === t && (e = 1, i.valiMsg("请阅读并同意服务协议"));
            break;

          case "tel":
            "" == t && (e = 1, i.valiMsg("请输入手机号码！")), 11 != t.length && (e = 1, i.valiMsg("您输入的手机号码有误！")), 
            /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/.test(t) || (e = 1, 
            i.valiMsg("您输入的手机号码有误！"));
        }
        return e;
    },
    valiMsg: function(a) {
      
        wx.showModal({
            content: a,
            showCancel: !1,
            confirmColor: "#cc0000"
        });
    },
  
  
  
   
    inputipone: function (e) {
      console.log(e.detail.value)
      this.setData({ipone: e.detail.value })
      // console.log(this.data.userImageBase64)
     

    },
    inputname: function (e) {
      console.log(e.detail.value)
      this.setData({name: e.detail.value })
      let $this = this;
      wx.request({
        url: this.data.userInfo.avatarUrl,
        method: 'GET',
        responseType: 'arraybuffer',
        success: function (res) {
          let base64 = wx.arrayBufferToBase64(res.data);
          $this.data.userImageBase64 = 'data:image/jpg;base64,' + base64;;
        }
      });

    },

});